package com.iskny.framework.session;

import javax.servlet.http.HttpSession;

abstract class AbstractSessionManager<T> implements ISessionManager<T>{

	protected HttpSession session;
	private String attrName;
	private AbstractSessionManager(){
		
	}
	public AbstractSessionManager(HttpSession session){
		this();
		this.session = session;
		setAttrName();
	}
	protected abstract void setAttrName();
	@Override
	public final String getAttrName() {
		return attrName;
	}

	@SuppressWarnings("unchecked")
	@Override
	public T getAttr() {
		return (T)session.getAttribute(attrName);
	}

	@Override
	public final void setAttr(T attr) {
		session.setAttribute(attrName, attr);
	}
	
	@Override
	public final void clear() {
		session.removeAttribute(attrName);
	}
	/**
	 * @param attrName
	 */
	void setAttrName(String attrName){
		this.attrName = attrName;
	}

}
